package com.niiwoo.civet.trade.service.local.notify.impl;

import com.niiwoo.civet.trade.dto.ProjectNotifyDTO;
import com.niiwoo.civet.trade.enums.NotifyTypeEnum;
import com.niiwoo.civet.user.dto.request.JPushExtDTO;
import com.niiwoo.civet.user.dto.request.UserLetterRequestDTO;
import com.niiwoo.civet.user.enums.JPushEnum;
import com.niiwoo.civet.user.enums.MessageTemplateKeyEnum;
import com.niiwoo.civet.user.enums.UserLetterTypeEnum;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

@Component
public class ProjectFlowMiscarryCancerManagerNotifier extends AbstractBorrowNotifier<ProjectNotifyDTO> {

    @Override
    protected List<? extends UserNotifyInfo> getUserNotifyInfoList(ProjectNotifyDTO projectNotifyDTO) {
        BorrowUserNotifyInfo info = new BorrowUserNotifyInfo();
        info.setUserId(projectNotifyDTO.getBorrowUserId());
        info.setProjectId(projectNotifyDTO.getProjectId());
        info.setProjectTitle(projectNotifyDTO.getTitle());
        info.setMobileNo(privacyMasks.decryptPrivacy(projectNotifyDTO.getBorrowMobile()));
        info.setPushContent(projectNotifyDTO.getPushContent());
        info.setProjectType(projectNotifyDTO.getType());
        info.setProjectFrom(projectNotifyDTO.getFromSource());
        return Collections.singletonList(info);
    }

    // 借款通过审核进入投资阶段，审核人员手动/批量流标
    // JS012 借款人
    // "通知 + 极光推送：借款项目流标通知 / 通知：您好，您的借款项目【项目名称】已流标。原因为：{后台审核人员填写的推送内容}
    @Override
    protected UserLetterRequestDTO getUserLetterRequestDTO(UserNotifyInfo info) {
        BorrowUserNotifyInfo p = (BorrowUserNotifyInfo) info;
        UserLetterRequestDTO letterRequest = new UserLetterRequestDTO();
        List<Object> letterParams = Arrays.asList(p.getProjectId(), p.getProjectTitle(), StringUtils.defaultIfBlank(p.getPushContent(), "信审手动流标"));
        // 通知
        letterRequest.setLetterTemplateEnum(MessageTemplateKeyEnum.LetterTemplateKeyEnum.PROJECT_FLOW_MISCARRY_CANCER_MANAGER);
        letterRequest.setLetterTemplateParamList(letterParams);
        // 极光推送
        List<Object> pushParams = Arrays.asList(p.getProjectTitle(), StringUtils.defaultIfBlank(p.getPushContent(), "信审手动流标"));
        letterRequest.setJpushTemplateKeyEnum(MessageTemplateKeyEnum.JPushTemplateKeyEnum.PROJECT_FLOW_MISCARRY_CANCER_MANAGER);
        letterRequest.setJpushTemplateParamList(pushParams);
        letterRequest.setToUserId(p.getUserId());
        letterRequest.setProjectId(p.getProjectId());
        letterRequest.setUserLetterTypeEnum(UserLetterTypeEnum.LETTER_AND_JPUSH);
        JPushExtDTO jPushExtDTO = new JPushExtDTO();
        jPushExtDTO.setRedirectPageEnum(JPushEnum.RedirectPageEnum.NOTICE_LIST_PAGE);
        letterRequest.setJPushExt(jPushExtDTO);
        return letterRequest;
    }

    @Override
    protected NotifyTypeEnum getType() {
        return NotifyTypeEnum.JS012;
    }

}
